// 编辑客户信息
function updateCustomerInfo() {
	$.ajax({
		type:"POST",
		data:$("#updateCustomerInfoForm").serialize(),
		url: basePath + "/customer/ajaxUpdateCustomerInfo",
		dataType:"json",
		success: function(data) {
			if (data.bizSuccess) {
				hideModal("#updateCustomerInfo");
				
				setTimeout(function() {
					customerInfo();
		        }, 500 );
				
			} else {
				alertErrorMsg(data.errorMsg);
			}
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

// 编辑ip段
function updateCustomerIpregion() {
	$.ajax({
		type:"POST",
		data:$("#updateCustomerIpregionForm").serialize(),
		url: basePath + "/worker/ajaxUpdateIPRegion",
		dataType:"json",
		success: function(data) {
			if (data.bizSuccess) {
				customerIpregion();
				hideModal("#updateCustomerIpregion");
			} else {
				alertErrorMsg(data.errorMsg);
			}
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

// 修改备注
function updateCustomerTrem() {
	$.ajax({
		type:"POST",
		data:{"remarks" : $("[name='remarks']").val(), "customerID" : customerID},
		url: basePath + "/customer/ajaxUpdateCustomerInfoTrem",
		dataType:"json",
		success: function(data) {
			if (data.bizSuccess) {
				customerInfo();
			} else {
				alertErrorMsg(data.errorMsg);
			}
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

function showTremnoupdate() {
	$(".tremnoupdate").show();
	$(".tremupdate").hide();
}

function hideTremnoupdate() {
	$(".tremnoupdate").hide();
	$(".tremupdate").show();
}

// 获取客户信息
function customerInfo() {
	ajaxHtml(basePath + "/customer/ajaxCustomerInfo", {"customerID" : customerID}, "customerinfo");
}

// 获取客户IP段信息
function customerIpregion() {
	ajaxHtml(basePath + "/worker/ajaxCustomerIpregion", {"customerID" : customerID}, "customeripregion");
}

function ajaxHtml(url, data, selector) {
	$.ajax({
		type:"POST",
		data:data,
		url:url,
		dataType:"html",
		success: function(data) {
			$(selector).html(data);
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

function ajaxJson(url, data) {
	$.ajax({
		type:"POST",
		data:data,
		url:url,
		dataType:"json",
		success: function(data) {
			if (data.bizSuccess) {
				
			} else {
				alertErrorMsg(data.errorMsg);
			}
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

// 获取ip段编辑弹窗
function getIpregionInfo() {
	if (ipregionListEmpty == '0') {
		alertErrorMsg("ip段为空");
		return;
	}
	
	$.ajax({
		type:"POST",
		data:{"customerID" : customerID},
		url:basePath + "/worker/ajaxGetIpregionInfo",
		dataType:"html",
		success: function(data) {
			$("updatecustomeripregion").html(data);
			showModal("#updateCustomerIpregion");
			$("#updateCustomerIpregionForm [name='customerID']").val(customerID);
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

// 添加和删除ip段输入框
function changeIpregionCount(e) {
	var obj = $(e).parents(".form-row").parent(".form-group");
	if ($(e).val() == 'x') {
		obj.remove();
	} else if ($(e).val() == '+') {
		var copyObj = obj.clone(true);
        $(obj).after(copyObj);
        $(e).text("x");
        $(e).attr("class","");
        $(e).addClass("close");
        $(e).val("x");
        $(copyObj).find("[name='ipStart']").val(null);
        $(copyObj).find("[name='ipEnd']").val(null);
	}
}

function deleteCustomerInfo() {
	confirmdemo("确认删除吗？", function() {
		affDeleteCustomerInfo()
	})
}

// 删除客户信息
function affDeleteCustomerInfo() {
	$.ajax({
		type:"POST",
		data:{"customerID":customerID},
		url:basePath + "/customer/ajaxDeleteCustomerInfo",
		dataType:"json",
		success: function(data) {
			if (data.bizSuccess) {
				location.href=basePath + '/console/customerList';
			} else {
				alertErrorMsg(data.errorMsg);
			}
		},
		error:function () {
			alertErrorMsg("请检查网络");
		}
	})
}

// 查看全部
function toWorkList() {
	$("#topSub #topCondition").val(customerName);
	$("#topSub").submit();
}
